<?php

/**
 * This is the model class for table "invoices".
 *
 * The followings are the available columns in table 'invoices':
 * @property integer $id
 * @property integer $user_id
 * @property string $school_status
 * @property string $membership_sought
 * @property string $monthly_tuition
 * @property integer $students
 * @property integer $ministry_gift
 * @property integer $total_payment
 * @property integer $status
 */
class Invoices extends CActiveRecord
{

  const STATUS_UNAPPROVED = 0;
  const STATUS_APPROVED = 1;
  
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Invoices the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'invoices';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('user_id, school_status, membership_sought, monthly_tuition, students, ministry_gift, total_payment, status', 'safe'),
			// array('user_id, students, ministry_gift, total_payment, status', 'numerical', 'integerOnly'=>true),
			// array('school_status, membership_sought, monthly_tuition', 'length', 'max'=>500),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, user_id, school_status, membership_sought, monthly_tuition, students, ministry_gift, total_payment, status', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
      'user' => array(self::BELONGS_TO, 'Users', 'user_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'user_id' => 'User',
			'school_status' => 'School Status',
			'membership_sought' => 'Membership Sought',
			'monthly_tuition' => 'Monthly Tuition',
			'students' => 'Students',
			'ministry_gift' => 'Ministry Gift',
			'total_payment' => 'Total Payment',
			'status' => 'Status',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('user_id',$this->user_id);
		$criteria->compare('school_status',$this->school_status,true);
		$criteria->compare('membership_sought',$this->membership_sought,true);
		$criteria->compare('monthly_tuition',$this->monthly_tuition,true);
		$criteria->compare('students',$this->students);
		$criteria->compare('ministry_gift',$this->ministry_gift);
		$criteria->compare('total_payment',$this->total_payment);
		$criteria->compare('status',$this->status);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}